package edu.jptest.serviceImp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import edu.jptest.bean.Group;
import edu.jptest.dao.GroupDAO;

public class GroupService {

	// 获得所有团体
	public List<Group> getAllGroups() {
		GroupDAO groupDAO = new GroupDAO();
		List<Group> groupList = new ArrayList<Group>();
		List<Integer> groupIdList = new ArrayList<Integer>();
		groupIdList = groupDAO.getAllGroupsId();
		Iterator<Integer> it = groupIdList.iterator();
		while (it.hasNext()) {
			int groupId = (Integer) it.next();
			groupList.add(groupDAO.getGroupById(groupId));
		}
		return groupList;
	}

	// 根据团体名、班级名得到团体对象
	public Group getGroupByName(String groupName, String className) {
		GroupDAO groupDAO = new GroupDAO();
		int group_id = groupDAO.getGroupIdByName(groupName, className);
		System.err.println("group_ID: "+group_id);
		if (group_id != 0) {
			return groupDAO.getGroupById(group_id);
		} else {
			return null;
		}
	}
}
